
 package com.sinven.interceptor;

 import javax.servlet.http.HttpServletRequest; import
 javax.servlet.http.HttpServletResponse; import
javax.servlet.http.HttpSession;
 
 import org.springframework.web.servlet.HandlerInterceptor;
 
 public class UserInterceptor implements HandlerInterceptor {
 
 public boolean preHandle(HttpServletRequest request,HttpServletResponse
 response, Object handler) throws java.lang.Exception{
 
// 取得Session对象 
	 HttpSession session = request.getSession(false);
if(session!=null && session.getAttribute("user")!=null){ return true; }
 //String path = request.getServletContext().getContextPath(); 
 String path = request.getRequestURI();
  System.out.println(path); 
  StringBuffer requestURL = request.getRequestURL(); //
 System.out.println(requestURL.toString());
 response.sendRedirect(path+"/login.jsp"); return false;
 
 
 
 } }
